<template>
    <div class="wrap">
         <van-nav-bar @click-left="onClickLeft" left-arrow left-text="返回" title="">
       
    </van-nav-bar>
        <van-notice-bar scrollable color="#1989fa" background="#ecf9ff" left-icon="info-o">
           当前好友上限{{friendNumber}}个，需要变更请联系物业
        </van-notice-bar>

        <van-contact-card type="add" @click="onAdd" />
        <van-contact-card
        v-for="(item,index) in list"
        :key="index"
        add-text="添加好友"
        type="edit"
        :name="item.name"
        :tel="item.phone"
        @click="onEdit(item)"
        />
    </div>
</template>
<script>
import { Notify,Dialog,Toast } from 'vant';
import api from '../api/myfriends.js'
    export default {
        data: function () {
            return {
                friendNumber:0,
                chosenContactId: '1',
                list: [
                   
                ],
               
                    
               
                
            }
        },
        components: {
           
        },
        created(){
           this.getlist()
           this.publicUser()
        },
        mounted() {
           
        },
        methods: {
             onClickLeft() {
               this.$router.go(-1)
            },
            publicUser(){
                let that=this
                api.publicUser().then(e=>{
                   
                    this.friendNumber=e.data.friendNumber
                }).catch(err=>{
                    console.log(err)
                })
            },
            getlist(){
                let that=this
                api.getlist({openId:openid}).then(e=>{
                    console.log(e)
                    that.list=e.data.map(item=>{
                        
                        switch(Number(item.userPermission)){
                            case 0:
                                item.messaget=item.name+'的相机权限：未知'
                                break;
                            case 1:
                                item.messaget='的相机权限：不允许,请上传清晰照'
                                break;
                            case 2:
                                item.messaget='的相机权限：允许'
                                break;
                            case 3:
                                item.messaget='的相机权限：失败'
                                break;
                        }
                        return item
                    })
                }).catch(err=>{
                    console.log(err)
                })
            },
            onEdit(item){
                
                this.$router.push({name:'frienddetail',query:{code:item.id}})
            },
            onAdd() {
                if(this.list.length>=this.friendNumber){
                    Toast(`最多添加${this.friendNumber}位好友，请联系物业添加更多`);
                    return
                }
                if(globalRole==1){
                    this.$router.push('/addfriends')
                }else{
                    if(globalRole==3){
                        this.$router.push('/addfriends')
                    }else{
                       Toast('最多添加四位好友，请联系物业添加更多'); 
                    }
                }
                
            }
           
           
           
        }
    }
</script>

<style scoped lang="scss">
@import "../common.scss";
  

</style>
